import { HttpClient } from "@angular/common/http";
import { Component, OnInit } from "@angular/core";
import { NavController } from "@ionic/angular";

@Component({
  selector: "app-sort",
  templateUrl: "./sort.page.html",
  styleUrls: ["./sort.page.scss"],
})
export class SortPage implements OnInit {
  constructor(public http: HttpClient, public router: NavController) {}
  major = ["玄幻", "异世", "修真", "仙侠", "江湖", "都市", "科幻"];
  minor = ["连载中", "完结"];
  num1 = 0;
  num2 = 0;
  res: Result;
  majorC = "玄幻";
  minorC = "连载中";
  showMajor(item) {
    let url =
      "http://xiaoshuogebed.applinzi.com/major?majorCate=" +
      item +
      "&minorCate=" +
      this.minorC;
    this.http.get(url).subscribe((res: Result) => {
      this.res = res;
      let majorCate = res.results[res.results.length - 1].majorCate;
      this.majorC = majorCate;
    });
  }
  showMinor(item) {
    let url =
      "http://xiaoshuogebed.applinzi.com/major?majorCate=" +
      this.majorC +
      "&minorCate=" +
      item;
    this.http.get(url).subscribe((res: Result) => {
      this.res = res;
    });
    this.minorC = item;
  }
  ngOnInit() {
    let url =
      "http://xiaoshuogebed.applinzi.com/major?majorCate=" +
      this.majorC +
      "&minorCate=" +
      this.minorC;
    this.http.get(url).subscribe((res: Result) => {
      this.res = res;
    });
  }
}
interface Result {
  code: number;
  message: string;
  results: result[];
}
interface result {
  author: string;
  bid: number;
  cover: string;
  latelyFollower: string;
  majorCate: string;
  male_id: number;
  minorCate: string;
  shortIntro: string;
  title: string;
}
